#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
#include <signal.h>

void cat_child(int);

int main(int argc,char** argv)
{
  pid_t pid;
  int i = 0;
  for(i = 0;i < 15;i++)
  {
    pid = fork();
    if(pid == 0)
    {
      return i + 1;
    }
  }
  
  struct sigaction act,old_act;
  act.sa_flags = 0;
  sigemptyset(&act.sa_mask);
  act.sa_handler = cat_child;
  sigaction(SIGCHLD,&act,&old_act);
  while(1);
  return 0;
}

void cat_child(int num)
{
  pid_t wpid;
  int status;
  while((wpid = wait(&status))!= -1)
  {
    printf("my pid is %d",wpid);
    if(WIFEXITED(status))
    {
      printf(" %d\n",WEXITSTATUS(status));
    }
  }
}
